﻿<%@ Control Language="C#" Inherits="Yuanlin.Business.CompanyFisheryEditControl, Yuanlin.Business" AutoEventWireup="true" %>

<%@Register tagPrefix="ctrl" tagName="Editor" src="~/themes/default/skins/Skin-HtmlEditor.ascx" %>

<script type="text/javascript">
<!--
    addEvent(window, "load", RestoreData);
    
    function RestoreData()
    {
        //规格
        var specificationHiddenField = document.getElementById('<%= specificationHiddenField.ClientID %>');
        var dyCreate = document.getElementById("dyCreate");
        if(specificationHiddenField.value.length>0)
        {
            CreateGuiGeControl(dyCreate,specificationHiddenField.value.split(";"));
        }
        
        var applicationSpecificationHiddenField = document.getElementById('<%= applicationSpecificationHiddenField.ClientID %>');
        var dyAppCreate = document.getElementById("dyAppCreate");
        if(applicationSpecificationHiddenField.value.length>0)
        {
            CreateGuiGeControl(dyAppCreate,applicationSpecificationHiddenField.value.split(";"));
        }
    }
    function CheckValue()
    {
        var title = document.getElementById('<%= titleValuedTextBox.ClientID %>');
        if(title.value.Trim().length==0)
        {
            alert('请填写常用名！');
            title.focus();
            return false;
        }
        else if(!isChinese(title.value.Trim()) || len(title.value.Trim())>5)
        {
            alert('常用名请输入汉字，并且最多只能输入5个汉字！');
            title.focus();
            return false;
        }
        
        var pinName = document.getElementById('<%= pinNameTitleValuedTextBox.ClientID %>');
        if(pinName.value.Trim().length > 0)
        {
            if(!isChinese(pinName.value.Trim()) || len(pinName.value.Trim())>5)
            {
                alert('品名请输入汉字，并且最多只能输入5个汉字！');
                pinName.focus();
                return false;
            }
        }
        
        var selected = false;
        var leng=0; 
        var rows=0;
        var childid;

        var category = document.getElementById('<%= categoryRadioButtonList.ClientID %>');
        if (category != null)
        {
            selected = false;
            rows = category.rows.length;
            for(var j=0;j<rows;j++)
            {
                leng=category.rows[j].cells.length; 
                for(var i=0;i<leng;i++)
                {
                  childid='<%= categoryRadioButtonList.ClientID %>'+'_'+(parseInt(j*leng)+parseInt(i));
                  if(document.getElementById(childid)!=null &&  document.getElementById(childid).checked)
                  {
                      selected = true;
                      break;
                  }      
                }
            }
            if(!selected)
            {
                alert('请选择植物分类！');
                return false;
            }
        }
        
        //植物分类的规格
        var specificationHiddenField = document.getElementById('<%= specificationHiddenField.ClientID %>');
        var dyCreate = document.getElementById('dyCreate');
        if(dyCreate.childNodes.length>0)
        {
            var values="";
            for(var i=0;i<dyCreate.childNodes.length;i++)
            {
                if(dyCreate.childNodes[i].childNodes[2].value.length>0 && !isNumber(dyCreate.childNodes[i].childNodes[2].value))
                {
                    alert('请在规格中输入数字！');
                    dyCreate.childNodes[i].childNodes[2].focus();
                    return false;
                }
                values+=";"+dyCreate.childNodes[i].childNodes[0].value+":"+dyCreate.childNodes[i].childNodes[2].value+":"+dyCreate.childNodes[i].childNodes[4].value;
            }
            if(values.length>0)
            {
                specificationHiddenField.value = values.substr(1);
            }
        }

        var number =  document.getElementById('<%= numberValuedTextBox.ClientID %>');
        if(number.value.Trim().length == 0)
        {
             alert('请填写数量！')
             number.focus();
             return false;
        }
        else
        {
            if(!isInteger(number.value.Trim()))
            {
                alert('数量应为整数！')
                number.focus();
                return false;
            }
            if(number.value.Trim().length>7)
            {
                alert('数量不能大于7位！')
                number.focus();
                return false;
            }
        }
        
        var price =  document.getElementById('<%= priceValuedTextBox.ClientID %>');
        if(price.value.Trim().length == 0)
        {
             alert('请填写价格！')
             price.focus();
             return false;
        }
        else
        {
            if(!isNumber(price.value.Trim()))
            {
                alert('价格应为数字！')
                price.focus();
                return false;
            }
            var overb = false;
            if(price.value.Trim().indexOf('.')>-1)//存在小数点
            {
                if(price.value.Trim().substr(0,price.value.Trim().indexOf('.')).length>7)
                {
                    overb=true;
                }
            }
            else if(price.value.Trim().length>7)
            {
                overb=true;
            }
            if(overb)
            {
                alert('价格不能大于7位！')
                price.focus();
                return false;
            }
        }
        
        var miJing =  document.getElementById('<%= miJingValuedTextBox.ClientID %>');
        if(miJing.value.Trim().length > 0)
        {
            if(!isNumber(miJing.value.Trim()))
            {
                alert('米径应为数字！')
                miJing.focus();
                return false;
            }
        }
        var diJing =  document.getElementById('<%= diJingValuedTextBox.ClientID %>');
        if(diJing.value.Trim().length > 0)
        {
            if(!isNumber(diJing.value.Trim()))
            {
                alert('地径应为数字！')
                diJing.focus();
                return false;
            }
        }
        if(miJing.value.Trim().length == 0 && diJing.value.Trim().length == 0)
        {
            alert('请填写米径或地径！')
            miJing.focus();
            return false;
        }
        
        var appchked=false;  
        var appcheckobj = document.getElementById('<%= applicationCategoryCheckBoxList.ClientID %>'); 
        var appchecks = appcheckobj.getElementsByTagName("input"); 
        var iappchecked = 0;
        for(var n=0;n <appchecks.length;n++) 
        { 
            if(appchecks[n].type== "checkbox" && appchecks[n].checked==true) 
            { 
               appchked=true; 
               iappchecked=iappchecked+1;
            } 
        } 
        if(!appchked)
        {
            alert('至少选择一个应用分类！');
            return false;
        }
        else if (iappchecked>5)
        {
            alert('最多选择5个应用分类！');
            return false;
        }
        
        var chked=false;  
        var checkobj = document.getElementById('<%= aquacultureMethodCheckBoxList.ClientID %>'); 
        var checks = checkobj.getElementsByTagName("input"); 
        var ichecked = 0;
        for(var n=0;n <checks.length;n++) 
        { 
            if(checks[n].type== "checkbox" && checks[n].checked==true) 
            { 
               chked=true; 
               ichecked=ichecked+1;
            } 
        } 
        if(!chked)
        {
            alert('至少选择一个种植方式！');
            return false;
        }
        else if (ichecked>2)
        {
            alert('最多选择两个种植方式！');
            return false;
        }
        
        var chkedseedling=false;  
        var seedlingattribute = document.getElementById('<%= aquacultureAttributeCheckBoxList.ClientID %>');
        var checksseedling = seedlingattribute.getElementsByTagName("input"); 
        var icheckedseedling = 0;
        for(var n=0;n <checksseedling.length;n++) 
        { 
            if(checksseedling[n].type== "checkbox" && checksseedling[n].checked==true) 
            { 
               chkedseedling=true; 
               icheckedseedling=icheckedseedling+1;
            } 
        } 
        if(!chkedseedling)
        {
            alert('至少选择1个苗木属性！');
            return false;
        }
        else if (icheckedseedling>3)
        {
            alert('最多选择3个苗木属性！');
            return false;
        }
        
        var registerTrademark = document.getElementById('<%= registerTrademarkValuedTextBox.ClientID %>');
        if (registerTrademark != null)
        {
            if(registerTrademark.value.Trim().length>0 && !isChinese(registerTrademark.value.Trim()))
            {
                alert('请在注册商标中输入汉字！')
                registerTrademark.focus();
                return false;
            }
        }
        
        return true;
    }
    
    function ClearOptions(list) 
    { 
        while (list.options.length > 0) 
        { 
            list.options[0] = null; 
        } 
    }
    function categoryClick()
    {
       var obj = document.getElementById('<%= categoryRadioButtonList.ClientID %>');
       var radInput = obj.getElementsByTagName("INPUT");   
       var radLable = obj.getElementsByTagName("Label");   
         
       for(var i=0;i<radInput.length;i++)   
       {   
         if(radInput[i].checked)   
          {   
              AjaxMethod.ParentCategorySelectedChanged('<%=ClientID %>', radInput[i].value,CategorySelectedChangedCallBack); 
          }   
       }   
    }
    function CategorySelectedChangedCallBack(res)
    {
        var dyCreate = document.getElementById("dyCreate");
        dyCreate.innerHTML="";
        
        if(res.value == null || res.value == "")
        {
            return;
        } 
        var specificationvalues=res.value;//规格
        if(specificationvalues.length>0)//规格
        {
            CreateGuiGeControl(dyCreate,specificationvalues.split(";"));
        }
    }
    
   function CreateGuiGeControl(dyCreate,values)
    {
        for(var i=0;i<values.length;i++)
        {
            if (values[i] == "")
            {
                continue;
            }
            var data = values[i].split(":");
            var div = document.createElement("div");
            div.style.marginTop="5px";
            div.style.paddingLeft="30px";
            div.style.width="28%";
            div.style.overflow="hidden";
            div.style.styleFloat="left"; 
            
            var input = document.createElement("input");
            input.setAttribute("type", "hidden"); 
            input.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldName"); 
            input.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldName"); 
            input.setAttribute("value",data[0]);
            
            var label = document.createElement("label");
            label.style.display="block";
            label.style.styleFloat="left";
            label.style.width="4em";
            label.style.paddingTop="0.5em";
            label.style.paddingRight="1em";
            label.style.textAlign="right";
            label.style.fontSize="12px"; 
            label.setAttribute("for", data[0]); 
            var textNode = document.createTextNode(data[0]); 
            label.appendChild(textNode);
            
            var inputFieldValue = document.createElement("input");
            inputFieldValue.setAttribute("type", "text"); 
            inputFieldValue.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldValue"); 
            inputFieldValue.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldValue"); 
            inputFieldValue.style.border="1px";
            inputFieldValue.style.borderStyle="solid";
            inputFieldValue.style.borderColor="#CCC";
            inputFieldValue.style.paddingTop="4px";
            inputFieldValue.style.width="30%";
            inputFieldValue.onchange=function(){
                if(inputFieldValue.value.Trim().length>0 && !isNumber(inputFieldValue.value.Trim()))
                {
                    alert('请在规格中输入数字！');
                    inputFieldValue.value="";
                }
            };
            if(data.length>2)
            {
                inputFieldValue.setAttribute("value",data[2]);
            }
            
            var labelproductunit = document.createElement("label");
            labelproductunit.style.width="16em";
            labelproductunit.style.paddingTop="0.5em";
            labelproductunit.style.paddingRight="1em";
            labelproductunit.style.textAlign="left";
            labelproductunit.style.fontSize="12px";
            var textNode = document.createTextNode(data[1]); 
            labelproductunit.appendChild(textNode);
            
            var inputFieldUnit = document.createElement("input");
            inputFieldUnit.setAttribute("type", "hidden"); 
            inputFieldUnit.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldUnit"); 
            inputFieldUnit.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldUnit"); 
            inputFieldUnit.setAttribute("value",data[1]);
            
            div.appendChild(input);
            div.appendChild(label);
            div.appendChild(inputFieldValue);
            div.appendChild(labelproductunit);
            div.appendChild(inputFieldUnit);
            
            dyCreate.appendChild(div);
        }
    }
    //-->
</script>
<asp:HiddenField ID="specificationHiddenField" runat="server" />
<asp:HiddenField ID="applicationSpecificationHiddenField" runat="server" />
<div class="AdminArea" style="height:900px;overflow-y:no;">
    <fieldset>
        <legend><asp:Literal ID="editProductLiteral" runat="server"></asp:Literal></legend>
        
        <div class="ThubnailImage">
			<nwap:YuanlinImage ID="yuanlinImage" runat="server" UseRealSize="true" ImageType="Details" Width="240" Height="130" PictureLink="true" DefaultFileName="defaultSiteSmallPic.gif" AttachmentName="CompanyFishery"/>
        </div>
        
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="titleValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Title" />
            </div>
            <nwap:ValuedTextBox Runat="server" AutoCompleteType="Disabled" CssClass="InputField MicroWidth" id="titleValuedTextBox" Enabled="false"/>
            <nwap:ResourceLabel runat="Server" ControlToLabel="aliasValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Alias" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField Width40" id="aliasValuedTextBox" Enabled="false"/>
        </div>
        
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="pinNameTitleValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_PinZhong" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MicroWidth" id="pinNameTitleValuedTextBox"/>
            <nwap:ResourceLabel runat="Server" ControlToLabel="attachmentData" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Pic" />
            <Input type="File" onchange="CheckImage(this)" id="attachmentData" class="InputField Width40" runat="server" name="attachmentData" />
        </div>
        
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="miJingValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_MiJing" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MicroWidth" id="miJingValuedTextBox" />cm
            <nwap:ResourceLabel runat="Server" ControlToLabel="diJingValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_DiJing" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MicroWidth" id="diJingValuedTextBox" />cm
            <nwap:ResourceLabel runat="Server" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_AvgPrice" />
            <asp:Label ID="avgPriceLtl" runat="server" style="border:1px;width :30px;text-align:right"></asp:Label>(元)
        </div>
        
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="numberValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Number" />
            </div>
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MicroWidth" id="numberValuedTextBox" />
            <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
            <nwap:ResourceLabel runat="Server" ControlToLabel="priceValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Price" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MicroWidth" id="priceValuedTextBox" />(元)
        </div>
        
        <div class="FormRow">
            <table width="100%">
                <tr valign="top">
                    <td style="width:100%">
                        <div class="LargerFieldNameRequireCharacter">
                            <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                            <nwap:ResourceLabel runat="Server" ControlToLabel="categoryRadioButtonList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_ProductCategory" />
                         </div>
                         <asp:RadioButtonList CssClass="CategoryCheckboxList" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" ID="categoryRadioButtonList" onclick="categoryClick()"/>
                    </td>
                </tr>
            </table>
	   </div>
        
        <div class="FormRow">
            <table width="100%">
                <tr valign="top">
                    <td style="width:100%">
                        <div id="dyCreate">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
          
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="aquacultureAttributeCheckBoxList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_AquacultureAttribute" />
            </div>
            <asp:CheckBoxList CssClass="CategoryCheckboxList" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" ID="aquacultureAttributeCheckBoxList" />
        </div>     
          
         <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="aquacultureMethodCheckBoxList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_AquacultureMethod" />
            </div>
            <asp:CheckBoxList CssClass="CategoryCheckboxList" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" ID="aquacultureMethodCheckBoxList" />
        </div> 
        
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="applicationCategoryRadioButtonList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_ApplicationCategory" />
            </div>
            <asp:CheckBoxList CssClass="CategoryCheckboxList" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" ID="applicationCategoryCheckBoxList" />
        </div>
       <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="registerTrademarkValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_RegisterTrademark" />
            <nwap:ValuedTextBox Runat="server" CssClass="InputField SmallWidth" id="registerTrademarkValuedTextBox" />
            <nwap:ResourceLabel runat="Server" ControlToLabel="productPriceFromFaceCheckBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_ProductPriceFromFace" />
            <nwap:ValuedCheckBox Runat="server" id="productPriceFromFaceCheckBox" />
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel  CssClass="FieldName" runat="Server" ControlToLabel="expiredInfoRadioButtonList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_ExpiredInfo" />
            <asp:RadioButtonList CssClass="CategoryCheckboxList" Width="600px" runat="server" RepeatDirection="Horizontal" RepeatColumns="7" ID="expiredInfoRadioButtonList" />
        </div> 
        
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="bodyValuedEditor" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_CompanyFishery_Body" />
            <br /><br /><ctrl:Editor Runat="server" Width="100%" Height="250px" id="descriptionValuedEditor" />
        </div>
        <div class="FormRow SubmitButtonRow">
            <nwap:Resourcebutton id="SaveButton" ResourceName="Save" CssClass="Button" Runat="server" OnClientClick="return CheckValue();"></nwap:Resourcebutton>&nbsp;&nbsp;&nbsp;&nbsp;
            <nwap:Resourcebutton id="BackButton" ResourceName="Back" CssClass="Button" Runat="server"></nwap:Resourcebutton>
        </div>	
    </fieldset>
</div> 